
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

/**
 *
 * @Problem: 10420 - List Of Conquests
 * @author Cesar Augusto Meneses Guzman
 * @version 1.0
 * @since 04 de Mayo de 2013
 */
public class ListOfConquests {

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(String[] args) throws NumberFormatException, IOException {
        Map<String, Integer> libro = new TreeMap<String, Integer>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		BufferedReader br = new BufferedReader(new FileReader(new File("inListOfConquests.txt")));

        int n = Integer.parseInt(br.readLine());

        while (n > 0) {
            String[] ciudad = br.readLine().split("[ ]+");
            if (libro.containsKey(ciudad[0])) {
                libro.put(ciudad[0], libro.get(ciudad[0]) + 1);
            } else {
                libro.put(ciudad[0], 1);
            }
            n = n - 1;
        }
//		br.close();
        Iterator<Entry<String, Integer>> libroIterator = libro.entrySet().iterator();
        while (libroIterator.hasNext()) {
            Entry<String, Integer> entry = libroIterator.next();
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}